#include "model.h"

Model::Model(Game* game) : GameObject(game) {
    this->model = NULL;
    this->modelFilename = NULL;
    this->texture = NULL;
    this->textureFilename = NULL;
}

Model::~Model(void) {
}

CMs3dModel* Model::GetModel() const {
    return this->model;
}

char* Model::GetModelFilename() const {
    return this->modelFilename;
}

void Model::SetModelFilename(char* val) {
    this->modelFilename = val;
}

CTexture* Model::GetTexture() const {
    return this->texture;
}

char* Model::GetTextureFilename() const {
    return this->textureFilename;
}

void Model::SetTextureFilename(char* val) {
    this->textureFilename = val;
}

void Model::Draw(float timeDelta) {
    this->Draw(this->GetWorldMatrix());
}

void Model::Draw(Matrix4x4 matrix) {
    if (this->model != NULL) {
        if (this->texture != NULL) {
            this->GetGame()->GetContentManager()->UseTexture(this->texture);
        }

        this->GetGame()->GetLightManager()->UploadLights(this->GetPosition());
        this->model->SetWorldMatrix(matrix);
        this->model->Render();
    }
}

void Model::Initialize() {
}

void Model::LoadContent() {
    if (this->modelFilename != NULL) {
        this->model = this->GetGame()->GetContentManager()->LoadModel(this->modelFilename);
        if (this->textureFilename != NULL) {
            this->texture = this->GetGame()->GetContentManager()->LoadTexture(this->textureFilename);
        } else {
            this->texture = this->GetGame()->GetContentManager()->LoadTexture(this->model->GetTextureName());
        }
    }
}

void Model::Update(float timeDelta) {
}
